home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-02-17 | 51.5 KB | 1,605 lines | [TEXT/ZBAS] |
- '
- ' QuickBASIC to FutureBASIC Conversion Program
- '
- ' ------------------------------------------------------
- '
- ' This program consists of four files:
- '
- ' QB Convert.BAS = source code of conversion program
- ' QB->FB.data = the actual conversion data required to
- ' successfully convert a keyword in QuickBASIC
- ' to FutureBASIC syntax
- ' qbCLR.INCL = an Include file containing functions that
- ' mimic the majority of Clear Lake Research
- ' calls that are not simple Toolbox translations.
- ' QB->FB Instructions = A read me file containing pointers and notes
- ' concerning these files and the translation
- ' process.
- '
- ' ------------------------------------------------------
- '
- ' WHAT THIS PROGRAM CAN DO:
- '
- ' This conversion program will translate a QuickBASIC source code file
- ' saved in TEXT format into a source code TEXT file FutureBASIC can use.
- ' It will ocnvert approximately 80% of the QB keywords into FB syntax including
- ' a majority of CLR and Toolbox calls. It will also convert multi-line
- ' IF/THEN statements into FB's LONG IF structures, change multi-statements
- ' line containing colons into single lines. Additionaly, it will convert QB
- ' subroutine labels to FB format and convert SUBs into LOCAL FNs.
- '
- ' It also attempts to mark every statement not converted with appropriate
- ' references to the Reference or Handbook manuals for help in fixing
- ' your source code.
- '
- ' ------------------------------------------------------
- '
- ' WHAT THIS PROGRAM CANNOT DO:
- '
- ' It cannot deduce your program structure. While every attempt has been
- ' made to make it as robust as possible in converting parameters, finding
- ' labels, or changing SUBs to LOCAL FNs, your method of programming can
- ' cause subtle errors to creep into the translated program.
- '
- ' Additionally, it does not attempt to rewrite any file handling routines
- ' included in the source file. There are just too many variables to trust
- ' an accurate translation and re-writing them is best left to the programmer
- ' to ensure the results are what they expect.
- '
- ' ALWAYS WORK ON A TEXT COPY OF THE ORIGINAL.
- ' (See the Read Me file for more info on this)
- '
- ' If errors are present feel free to modify the source code to correct
- ' these deficiencies. The source code is provided AS IS with no guarantee
- ' of any results. The majority of routines have been documented to provide
- ' as much help as possible to make additions or changes relatively easy.
- ' Again, feel free to change or modify as necessary to best suit your
- ' purposes.
- '
- ' If you do modify the program, please provide as much documentation as
- ' as you can, and if distributing, be sure to include ALL the files mentioned
- ' above to keep the package complete for the next user.
- '
- '
- ' ------------------------------------------------------
- '
- '
- _debug = 0
- COMPILE LONG IF _debug
- TRON b
- COMPILE END IF
- '
- '----------------------- Constants ---------------------
-
- COMPILE 0, _Macsbuglabels
-
-
- _maxKeywords = 300
-
- _qb = 0
- _fb = 1
-
- _srcIndx = 0
- _remIndx = 1
- _hedIndx = 2
- _labelIndx = 3
- _ifIndx = 4
-
- _rem = _"'"
- _space = _" "
- _quote = 34
- _comma = _","
- _colon = _":"
- _openP = _"("
- _closeP = _")"
- _bullett = _"•"
- _caret = _"^"
- _pound = _"#"
- _att = _"@"
- _asterisk = _"*"
-
-
- _MaxFns = 25
-
-
- '----------------------- Globals -----------------------
-
- DIM 63 gFilename$ 'name of output file
- DIM gTotalLines
- DIM buff.200
- DIM gExitSub
- DIM gHeaderLines
- DIM gTotalIFs
-
- DIM 255 gStmnts$(20)
- DIM 63 gLabel$ (_maxKeywords)
- DIM 63 gSubs$ (_maxKeywords)
- DIM 63 gConv$ (_fb,_maxKeywords) '0 = QB keyword, 1 = FB equivalent
- DIM 99 gParam$ (9) 'array to hold parameters in statement
- DIM 99 gStmnt$ (9) 'array of actual line statements
-
- DIM gProfile& (_MaxFNs)
-
- END GLOBALS
-
- CLEAR 5000, _hedIndx
- CLEAR 1500, _ifIndx
- CLEAR 2000, _labelIndx
- CLEAR 5000, _remIndx
- CLEAR 5000, _srcIndx
-
-
- '----------------------- Functions ---------------------
-
-
-
- LOCAL FN StartFN (FNID%)
- gProfile& (FNID%) = gProfile& (FNID%) - FN TICKCOUNT
- END FN
-
-
-
- LOCAL FN StopFN (FNID%)
- gProfile& (FNID%) = gProfile& (FNID%) + FN TICKCOUNT
- END FN
-
-
-
- LOCAL FN PrintFNCounts
- CLS
- FOR j = 1 TO _MaxFNs
- IF gProfile& (j) <> 0 THEN PRINT j,gProfile& (j)
- NEXT j
- END FN
-
-
- LOCAL FN doAlrt(s$)
- CALL PARAMTEXT(s$,"","","")
- item = FN STOPALERT(4,0)
- END FN = item
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine checks the free space in the specified INDEX$ and increases
- ' it if there isn't enough. It also tacks on a requested spare amount to
- ' reduce the number of times it must be changed.
- '
- ' size& = number of bytes required free in INDEX$
- ' indxID = ID of the INDEX$ to check
- ' spare& = size of spare bytes to add in addition to size&
- '
- LOCAL FN CheckIndexSize (size&, indxID, spare&) 'is index large enough
- indxSize& = MEM(indxID + _availBytes) 'num bytes available in INDEX$
- crntSize& = MEM(indxID + _maxBytes) 'max bytes available to index$
- LONG IF indxSize& < size& 'less than requested size
- CLEAR crntSize& + size& + spare&, indxID 'increase with size & spare
- LONG IF MEM(indxID + _maxBytes) = crntSize& 'was INDEX$ resized?
- BEEP : SYSERROR = _memFullErr 'if no change we are out of memory
- END IF
- END IF
- END FN
-
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine strips any designated character from the front of a string
- ' and replaces the original string with the modified one.
- '
- ' charPos = the char position in the string
- ' strPtr& = pointer to string to operate on
- ' newLen% = length of new line after stripping
- '
- LOCAL FN stripLeadChar (@strPtr&, char, charPos) 'string addr and char to strip out
- WHILE PEEK(strPtr& + charPos) = char 'is this the char we are striping?
- INC (charPos) 'yes, keep adding to count
- WEND 'until letter <> char
- newLen% = PEEK(strPtr&) - charPos + 1 'calc new length of string
- BLOCKMOVE strPtr& + charPos, strPtr& + 1, newLen% 'blockmove end of string to front
- POKE strPtr&, newLen% 'poke new length
- END FN 'we are done!
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine strips any remarks from a line of source code and stores
- ' it in a second INDEX$. the two are re-combined when the file is output
- ' to disk.
- '
- ' source$ = source code line to strip remark from
- '
- LOCAL FN remarkBlaster$ (source$) 'removes remarks from lines
- remark$ = "" 'clear remark string
- remarkPos = INSTR(1, source$, "REM") 'is there a REM in it?
- apostrPos = INSTR(1, source$, "'") 'is there a apostrophe in it?
-
- LONG IF remarkPos <> 0 OR apostrPos <> 0 'if we got either
- LONG IF remarkPos => apostrPos AND remarkPos <> 0
- apostrPos = remarkPos 'mark sure we get the first occurance
- END IF
-
- remark$ = RIGHT$(source$, LEN (source$) - apostrPos)'strip remark from line
- source$ = LEFT$(source$, apostrPos - 1) 'strip source code from line
-
- DEF TRUNCATE (source$) 'delete any trailing spaces
- DEF TRUNCATE (remark$)
- FN stripLeadChar (remark$, _space, 1) 'strip leading spaces from line
-
- FN CheckIndexSize (LEN(remark$), _remIndx, 500) 'make room in remark INDEX$
- LONG IF SYSERROR = _noErr
- INDEX$ (gTotalLines, _remIndx) = remark$ 'place remark into its own INDEX$
- END IF
- END IF
- END FN = source$
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine allows the user to select a TEXT file for conversion using
- ' a standard getfile dialog, then reads the source file into an INDEX$
- ' array for easier manipulation. as it reads the file in it disposes of
- ' any leading space characters and strips all remarks from the line.
- ' additionally, the window name is changed to show which file is being
- ' converted.
- '
- LOCAL
- DIM 255 source$
- LOCAL FN OpenFile 'open QB source code into Index$ array zero
- gFilename$ = FILES$(_fOpen, "TEXT" ,,volRefNum%)
- LONG IF LEN(gFilename$)
- CURSOR _watchCursor
- OPEN "I", 1, gFilename$, , volRefNum% 'open source code file
- byte& = LOF(1,1) 'get file size
- FN CheckIndexSize (byte&, _srcIndx, 5000) '50K buffer
- LONG IF SYSERROR = _noErr
- filename$ = "Converting: " + gFilename$
- WINDOW #1, filename$ 'show conversion name in window
- CLS
-
- gTotalLines = 0
- DO
- LONG IF (gTotalLines MOD 10) = 0
- PRINT%(10,20) "Importing original source code…"
- PRINT%(10,40) "Reading line #";gTotalLines
- END IF
-
- LINE INPUT #1, source$ 'get next source code line
-
- FN stripLeadChar (source$, _space, 1) 'strip leading spaces from line
- source$ = FN remarkBlaster$ (source$) 'strip remarks from line
-
- INDEX$(gTotalLines, _srcIndx) = source$ 'put massaged source into INDEX$
- INC(gTotalLines)
- UNTIL EOF(1)
- CLOSE #1
- XELSE
- item = FN doAlrt ("Not enough memory to convert this program!")
- END
- END IF
- END IF
- CALL INITCURSOR
- END FN
-
-
-
-
-
-
-
-
- ' -----------------------------------------------------------------
- ' works like MID$ except that it can grow or shrink the string as
- ' required when inserting the replacement text
- '
- '
- LOCAL FN replaceSomething (@srcPtr&, charPos, @oldkeyPtr&, @newKeyPtr&)
- strSize = PEEK (srcPtr&) 'get original size of source string
- oldKeySz = PEEK (oldkeyPtr&) 'get old key size
- newKeySz = PEEK (newKeyPtr&) 'get new key size
- startPtr& = srcPtr& + charPos + oldKeySz
- endPosPtr& = startPtr& + (newKeySz - oldKeySz)
- moveSize = strSize - charPos + 1 'calc num chars to move
- newSize = strSize + (newKeySz - oldKeySz) 'calc new string size
- LONG IF newSize < 256 'still within max string length?
- BLOCKMOVE startPtr&, endPosPtr&, moveSize
- BLOCKMOVE newKeyPtr& + 1, srcPtr& + charPos, newKeySz'replace old key with new
- POKE srcPtr&, newSize 'set string to new size
- XELSE
- SYSERROR = _memSCErr 'size check failed error
- END IF
- END FN
-
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine sets up the program window and some default
- ' program and window attributes
- '
- LOCAL FN initialize
- WIDTH _noTextWrap 'faster
- gVolRefNum% = SYSTEM (_aplVol) 'this is where I'll save the output file
- WINDOW #1,"QB Convert", (0,0)-(400,200), _docNoGrow _NoGoAway
- TEXT _monaco, 9, , 0
- END FN
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine converts a QB label to an FN label title format
- '
- ' label$ = label title being converted from QB->FB format
- '
- LOCAL FN quoteMe$ (label$)
- label$ = CHR$(_quote) + label$ + CHR$(_quote)
- END FN = label$
-
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine adds the components of a parsed string into separate
- ' lines in the source code. it also ensures that adequate memory is
- ' available to add the new lines and keeps remarks lined up with the
- ' original string location
- '
- ' lineNum = line number in source code to add new lines
- ' statCount = number of lines to add to source code
- '
- LOCAL FN insertFix (lineNum, statCount) 'inserts parsed lines into program
- LONG IF statCount > 0
- INDEX$ D (lineNum, _srcIndx) 'remove original
- DEC(gTotalLines) 'decrement line count
-
- size = 0
- FOR count = 0 TO statCount 'how much memory do we need?
- size = size + LEN(gStmnts$(count)) 'add each new line to total
- NEXT
- FN CheckIndexSize (size, _srcIndx, 5000) 'make sure we have enough mem
- FN CheckIndexSize (2 * statCount, _remIndx, 50)
-
- LONG IF SYSERROR = _noErr 'no memory error
- FOR count = statCount - 1 TO 0 STEP -1
- INDEX$ I (lineNum, _srcIndx) = gStmnts$(count) 'insert new source line
- LONG IF count <> 0 'skip all but original line
- INDEX$ I (lineNum + 1, _remIndx) = "" 'to keep remarks lined up
- END IF
- INC(gTotalLines) 'make sure we keep total lines right
- NEXT
- END IF
- END IF
- END FN
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine strips quoted strings from a designated string. it looks for
- ' a quote then begins replacing each subsequent char with a space until
- ' an ending quote is found.
- '
- ' source$ = the string to strip quoted strings from
- '
- LOCAL FN quoteBlaster$ (source$)
- counter = 1
- skip = _false
- strPtr& = @source$ 'get pointer to our string
- size% = PEEK(strPtr&) 'get string size
- WHILE counter <= size%
- char = PEEK(strPtr& + counter) 'get next char in string
- LONG IF char = _quote
- DEF TOGGLE (skip) 'toggle our flag
- POKE strPtr& + counter, _space 'space over quoted areas
- END IF
- IF skip = _zTrue THEN POKE strPtr& + counter, _space'space over all chars
- INC(counter)
- WEND
- END FN = source$
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine strips spaces from the end of a designated string
- '
- ' source$ = the string to strip spaces from
-
- LOCAL FN stripTrailingSpaces$ (source$)
- DEF TRUNCATE (source$)
- END FN = source$
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine gets the chars in the designated string from the starting
- ' position until a space, comma, colon, or open parenthesis is located.
- '
- ' charPos = position to begin char stripping
- ' source$ = the string to strip chars from
- ' endPosPtr& = pointer to endPos var in calling routine
- '
- LOCAL FN getChars$ (@charPosPtr&, source$, @endPosPtr&)
- temp$ = ""
- strPtr& = @source$
- strSize = PEEK (strPtr&)
- charPos = {charPosPtr&}
- WHILE PEEK(strPtr& + charPos) = _space
- INC (charPos)
- WEND
- startPos = charPos
- DO
- INC (charPos)
- char = PEEK(strPtr& + charPos)
- UNTIL char = _space OR char = _colon OR char = _comma OR char = _openP
- POKE WORD charPosPtr&, startPos
- POKE WORD endPosPtr&, charPos
- END FN = MID$(source$, startPos, charPos - startPos)
-
-
-
-
-
-
-
- LOCAL FN parseOnBranches$ (source$, srcTmp$, keywd$, @strPtr&, @lCountPtr&)
- TRON p
- labelCount = {lCountPtr&}
- LONG IF PEEK(strPtr&) > LEN (keywd$)
- MID$ (source$, 1, 3) = " "
- tpos = INSTR(1, source$, keywd$)
- tpos = INSTR(tpos, source$, " ") + 1 'parse from comma. GOSUB parse will get first label
- WHILE tpos
- 'TRON x
- temp$ = FN getChars$ (tpos, source$, endPos)
- DEF TRUNCATE (temp$)
-
- matchFound = _false
- FOR g = 0 TO labelCount
- LONG IF UCASE$(gLabel$(g)) = UCASE$(temp$)
- matchFound = _true
- temp$ = gLabel$(g) 'might have different case
- g = labelCount 'end loop search
- END IF
- NEXT
-
- LONG IF matchFound = _false
- gLabel$(labelCount) = temp$
- INC(labelCount)
- END IF
-
- search$ = temp$
- temp$ = FN quoteMe$ (temp$)
- FN replaceSomething (srcTmp$, tpos, search$, temp$)
- FN replaceSomething (source$, tpos, search$, temp$)
-
- BLOCKMOVE @source$, strPtr&, LEN(source$) + 1
- tpos = INSTR(tpos, source$, ",")
- IF tpos <> 0 THEN INC(tpos)
- WEND
-
- % lCountPtr&, labelCount 'poke count back into var
- END IF
- END FN = srcTmp$
-
-
-
- LOCAL FN parseRegBranch$ (source$, srcTmp$, keywd$, @strPtr&, @lCountPtr&, goPos)
-
- labelCount = {lCountPtr&}
- tpos = 1 'set initial position
- sLen = INSTR (goPos + LEN (keywd$), source$, " ") + 1
- temp$ = FN getChars$ (sLen, source$, endPos)
- DEF TRUNCATE (temp$)
- matchFound = _false
-
- FOR g = 0 TO labelCount - 1
- LONG IF UCASE$(gLabel$(g)) = UCASE$(temp$) 'is there a match?
- matchFound = _true 'set flag true
- temp$ = gLabel$(g) 'might have different case
- g = labelCount 'end loop search
- END IF
- NEXT
-
- LONG IF matchFound = _false
- gLabel$(labelCount) = temp$
- INC(labelCount)
- END IF
-
-
- search$ = temp$
- temp$ = FN quoteMe$ (temp$)
- FN replaceSomething (srcTmp$, sLen, search$, temp$)
- FN replaceSomething (source$, sLen, search$, temp$)
-
- BLOCKMOVE @source$, strPtr&, LEN(source$) + 1
- % lCountPtr&, labelCount 'poke count back into var
- END FN = srcTmp$
-
-
-
-
- SEGMENT
-
-
-
-
- ' -----------------------------------------------------------------
- ' source$ = source line to work upon
- ' maxLabels = number of labels to search for
-
- LOCAL FN checkForLabel$ (source$, maxLabels)
- compare$ = UCASE$ (source$)
- FOR labelCount = 0 TO maxLabels 'look for all labels on line
- thisLabel$ = UCASE$(gLabel$(labelCount))
- quoteLabel$ = FN quoteMe$ (gLabel$(labelCount))
-
- '---- this section updates the THEN and ELSE label GOTO's on a line
- tpos = INSTR(1, compare$, thisLabel$)
- LONG IF tpos - 5 > 0
- WHILE INSTR(tpos-5, compare$, "THEN") = tpos-5 OR INSTR(tpos-5, compare$, "ELSE") = tpos-5
- lab$ = "GOTO " + quoteLabel$ 'inserts GOTO into line
-
- x$ = LEFT$(compare$, tpos -1)
- LONG IF tpos + 1 < LEN(compare$)
- x2$ = MID$(compare$, tpos + LEN(gLabel$(labelCount)), 255) + " "
- XELSE
- x2$ = ""
- END IF
-
- y$ = LEFT$(source$, tpos -1)
- LONG IF tpos + 1 < LEN(source$)
- y2$ = MID$(source$, tpos + LEN(thisLabel$), 255)+" "
- XELSE
- y2$ = ""
- END IF
-
- source$ = y$ + lab$ + y2$
- compare$ = x$ + lab$ + x2$
-
- tpos = INSTR(tpos + 1, source$, thisLabel$)
- 'TRON x
- WEND
- END IF
-
- '---- Updates label on the line
- tpos = INSTR(1, compare$, thisLabel$)
- LONG IF VAL(gLabel$(labelCount)) 'if line num add a colon after it
- addColon$ = ":"
- XELSE 'otherwise make sure there is a colon after it!
- addColon$ = ""
- char = PEEK(@compare$ + LEN(gLabel$(labelCount)) + 1)
- END IF
-
- LONG IF tpos <> 0 'updates line with the quoted label
- LONG IF tpos = 1
- FN replaceSomething (source$, tpos, thisLabel$, quoteLabel$)
- XELSE
- minusOne = PEEK (@source$ + tpos - 1)
- plusOne = PEEK (@source$ + LEN (thisLabel$) + 1)
- LONG IF minusOne = _space AND plusOne = _space
- FN replaceSomething (source$, tpos, thisLabel$, quoteLabel$)
- END IF
- END IF
-
- LONG IF char = _colon
- charPos = INSTR (LEN(quoteLabel$), source$, ":")
- LONG IF charPos = LEN(quoteLabel$) + 1
- tmp$ = ":" : tmp2$ = ""
- FN replaceSomething (source$, charPos, tmp$, tmp2$)
- END IF
- END IF
- labelCount = maxLabels + 1 'end search
- END IF
- NEXT labelCount
- END FN = source$
-
-
-
-
-
- LOCAL
- DIM startPos, endPos
- LOCAL FN parseLabels
- labelCount = 0 'label count
- subCount = 0 'sub count
- CLS
- FOR lnCount = 0 TO gTotalLines
- LONG IF lnCount MOD 10 = 0
- PRINT%(10,20) "Creating label tables…"
- PRINT%(10,40) "Currently on line#";lnCount
- PRINT%(10,60) "Label count =";labelCount
- PRINT%(10,80) "SUB count =";subCount
- END IF
-
- source$ = INDEX$(lnCount, _srcIndx)
-
- LONG IF source$ <> "" 'skip all blank lines
- srcTmp$ = source$
- source$ = FN quoteBlaster$(srcTmp$) 'strip quoted stuff from string
-
- '•• Parse --- SUB labels
- tpos = INSTR(1,source$,"SUB ")
- LONG IF tpos = 1 'only first position counts
- tpos = tpos+3
- temp$ = FN getChars$ (tpos, source$, endPos)
- matchFound = _false
- FOR g = 0 TO subCount
- LONG IF UCASE$(gSubs$(g)) = UCASE$(temp$)
- matchFound = _true
- temp$ = gSubs$(g) 'might have different case
- g = subCount 'end loop search
- END IF
- NEXT
- LONG IF matchFound = _false
- gSubs$(subCount) = temp$
- INC(subCount)
- END IF
-
- END IF
-
- '•• Parse --- ON GOSUB ---
- goPos = INSTR(1, source$, "GOSUB") 'ON GOSUB labels line
- LONG IF goPos <> 0
- onPos = INSTR(1, source$, "ON ") 'ON GOSUB labels line
- LONG IF onPos = 1
- srcTmp$ = FN parseOnBranches$ (source$, srcTmp$, "GOSUB", source$, labelCount)
- XELSE
- srcTmp$ = FN parseRegBranch$ (source$, srcTmp$, "GOSUB", source$, labelCount, goPos)
- END IF
- END IF
-
- goPos = INSTR(1, source$, "GOTO") 'ON GOSUB labels line
- LONG IF goPos <> 0
- onPos = INSTR(1, source$, "ON ") 'ON GOSUB labels line
- LONG IF onPos = 1
- srcTmp$ = FN parseOnBranches$ (source$, srcTmp$, "GOTO", source$, labelCount)
- XELSE
- srcTmp$ = FN parseRegBranch$ (source$, srcTmp$, "GOTO", source$, labelCount, goPos)
- END IF
- END IF
-
- INDEX$(lnCount, _srcIndx) = srcTmp$ 'put the revised line back
- END IF
- NEXT lnCount
-
- COMPILE LONG IF _debug
- TROFF
- COMPILE END IF
-
- 'use list to replace all labels with dbl-quoted UCASE labels
- '
- CLS
- FOR y = 1 TO gTotalLines 'look through all the lines
-
- LONG IF y MOD 10 = 0
- PRINT%(10,20) "Updating actual labels…"
- PRINT%(10,40) "Currently updating line#";y
- END IF
-
- source$ = INDEX$(y, _srcIndx)
- FN stripLeadChar(source$, _space, 1)
- srcTmp$ = source$ 'get line without remark in it
- source$ = FN quoteBlaster$(srcTmp$) 'strip quoted stuff from string
- source$ = UCASE$(source$) 'labels are case insensitive
-
- LONG IF sCount
- FOR z = 0 TO sCount - 1
-
- '---- Update the SUB name to be FN subname
- temp$ = UCASE$(gSubs$(z))
-
- tpos = INSTR(1, source$, temp$)
- WHILE tpos AND (INSTR(1, source$,"SUB") > 1 OR INSTR(1, source$,"SUB") = 0)
- cpos = INSTR(1,source$, "CALL")
- LONG IF cpos = tpos - 5 'is there a CALL in front of subname?
- LONG IF cpos > 1 'strip the CALL out of the line
- x$ = LEFT$(source$,cpos-1)
- y$ = LEFT$(srcTmp$,cpos-1)
- XELSE
- x$ = "": y$ =""
- END IF
- x2$ = RIGHT$(source$, LEN(source$) - (cpos + 3))
- y2$ = RIGHT$(srcTmp$, LEN(srcTmp$) - (cpos + 3))
-
- source$ = x$ + x2$
- srcTmp$ = y$ + y2$
-
- tpos = INSTR(1,source$,temp$) 'get new position
- END IF
-
-
- '•• insert FN in front of SUB call
- LONG IF PEEK(@source$+tpos+LEN(temp$)) <> _openP AND PEEK(@source$+tpos+LEN(temp$)+1) <> _openP
- paren1$ = "("
- elsePos = INSTR(1,source$,"ELSE")
- FOR tt = tpos TO LEN(source$)
- LONG IF PEEK(@source$+tt) = _colon OR tt = LEN(source$) OR tt = elsePos
-
- bu = 1 'calculate how much to backup
- WHILE PEEK(@source$+tt-bu) = _space
- INC(bu)
- 'TRON x
- WEND
-
- x$ = LEFT$(srcTmp$, tt - bu)
- LONG IF tt +1 < LEN(srcTmp$)
- x2$ = MID$(srcTmp$, tt, 255)+" "
- XELSE
- x2$ = ""
- END IF
-
- y$ = LEFT$(source$, tt - bu)
- LONG IF tt +1 < LEN(source$)
- y2$ = MID$(source$, tt, 255)+" "
- XELSE
- y2$ = ""
- END IF
- source$ = y$ + ") " + y2$
- srcTmp$ = x$ + ") " + x2$
-
- tt = LEN(source$)
- END IF
- NEXT
-
- XELSE
- paren1$ = ""
- END IF
-
- lab$ = "FN " + gSubs$(z) +" " + paren1$ :'inserts FN in front of sub call
-
- x$ = LEFT$(srcTmp$, tpos -1)
- LONG IF tpos +1 < LEN(srcTmp$)
- x2$ = MID$(srcTmp$, tpos+LEN(gSubs$(z))+1, 255)+" "
- XELSE
- x2$ = ""
- END IF
-
- y$ = LEFT$(source$, tpos -1)
- LONG IF tpos +1 < LEN(source$)
- y2$ = MID$(source$, tpos+LEN(gSubs$(z))+1, 255)+" "
- XELSE
- y2$ = ""
- END IF
-
- source$ = y$ + SPACE$(LEN(lab$)) + y2$ : 'don't insert sub name into source$
- srcTmp$ = x$ + lab$ + x2$ : 'only srcTmp$
-
- tpos = INSTR(1, source$, temp$)
- 'TRON x
- WEND
- NEXT
- END IF
-
- LONG IF srcTmp$ <> ""
- srcTmp$ = FN checkForLabel$ (srcTmp$, labelCount)
- END IF
-
- WHILE VAL(srcTmp$) 'strip line numbers now
- srcTmp$ = RIGHT$(srcTmp$, LEN(srcTmp$)-1)
- WEND
-
- INDEX$(y, _srcIndx) = srcTmp$ 'put the revised line back
- NEXT
-
- END FN
-
-
-
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine converts IF THEN/ELSE statements to LONG IF/XELSE
- '
- ' srcCount = element in source code INDEX$
- '
- LOCAL FN parseXelse$ (srcCount) 'fix IF-THEN-ELSE to LONG IF - XELSE
- source$ = INDEX$ (srcCount, _srcIndx) 'get source line
- LONG IF source$ <> "" 'if it isn’t empty
- INDEX$ (srcCount, _srcIndx) = source$ 'get source line
- END IF
- END FN
-
-
-
-
-
- ' ------------------------------------------------------------------------
- '
- LOCAL FN parseIfThens (srcCount)
- source$ = INDEX$ (srcCount, _srcIndx)
-
- LONG IF source$ <> ""
- ifPos = INSTR (1, source$, "IF")
-
- LONG IF ifPos > 0
- elsePos = INSTR (1, source$, "ELSEIF")
- endPos = INSTR (1, source$, "END IF")
- thenPos = INSTR (ifPos, source$, "THEN")
-
- LONG IF (ifPos < thenPos) AND (thenPos = PEEK(@source$) - 3)
- LONG IF (ifPos - 4) = elsePos
- INC (gTotalIFs)
- search$ = "ELSEIF" : replace$ = "XELSE IF"
- FN replaceSomething (source$, elsePos, search$, replace$)
- ifPos = INSTR (1, source$, "IF")
- LONG IF ifPos <> 0
- INDEX$ I(srcCount + 1, _srcIndx) = MID$ (source$, ifPos, LEN (source$))
- INDEX$ I(srcCount + 1, _remIndx) = ""
- source$ = LEFT$ (source$, ifPos - 1)
- INC (gTotalLines)
- END IF
- END IF
-
-
- LONG IF ifPos = 1
- search$ = "IF" : replace$ = "LONG IF"
- FN replaceSomething (source$, ifPos, search$, replace$)
- END IF
-
-
- thenPos = INSTR (ifPos, source$, "THEN")
- LONG IF thenPos <> 0
- search$ = "THEN" : replace$ = ""
- FN replaceSomething (source$, thenPos, search$, replace$)
- END IF
- XELSE
- LONG IF (ifPos - 4) = endPos
- LONG IF gTotalIFs > 0
- FOR count = 1 TO gTotalIFs
- INDEX$ I(srcCount + 1, _srcIndx) = "END IF"
- INDEX$ I(srcCount + 1, _remIndx) = ""
- INC (gTotalLines)
- NEXT count
- gTotalIFs = 0
- END IF
- END IF
- END IF
-
- DEF TRUNCATE (source$)
- INDEX$ (srcCount, _srcIndx) = source$
- END IF
- END IF
- END FN
-
-
-
-
-
-
-
- LOCAL
- DIM quotePairs (40,1) 'dbl-quate pairs
- LOCAL FN parseLineColons (lineNum)
- count = 0
- DO
- gStmnts$(count) = ""
- INC (count)
- UNTIL gStmnts$(count) = ""
-
- source$ = INDEX$(lineNum, _srcIndx)
- srcTmp$ = source$
- source$ = FN quoteBlaster$(srcTmp$) 'strip quoted stuff from string
-
- DEF TRUNCATE (source$)
- statCount = 0 'Ok, now parse out the statements into gStmnts$(n)
- LONG IF remarkPos <> 1 'if remark is first pos then skip parse
- found = INSTR(1, source$, ":")
- LONG IF found = 0
- gStmnts$(0) = srcTmp$
- remarks$ = ""
- INC(statCount)
- XELSE
- WHILE found 'ok, let's look for colons
- gStmnts$(statCount) = LEFT$(srcTmp$, found -1) 'get statement
- srcTmp$ = RIGHT$(srcTmp$, LEN(srcTmp$)-found) 'peel off unparsed section
- source$ = RIGHT$(source$, LEN(source$)-found) 'peel off unparsed section
- INC(statCount)
- found = INSTR(1, source$, ":")
- 'TRON x
- LONG IF found = 0
- gStmnts$(statCount) = srcTmp$
- INC(statCount)
- END IF
- WEND
- END IF
- END IF
-
- FN stripLeadChar (gStmnts$(statCount), _space, 1) 'strip leading spaces
- FN insertFix(lineNum,statCount)
-
- END FN = statCount
-
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine parses any IF statements into multiple lines and converts
- ' single line multiple statements (separated by colons) in multiple line
- ' single statement lines.
- '
- LOCAL FN fixLineRefs
- CLS
- FOR lnCount = 0 TO gTotalLines
- LONG IF lnCount MOD 10 = 0
- PRINT%(10,20) "Parsing IF statements…"
- PRINT%(10,40) "Currently on line#";lnCount
- END IF
- FN parseIfThens (lnCount)
- NEXT
-
- CLS
- FOR lnCount = 0 TO gTotalLines
- 'TRON x
- LONG IF lnCount MOD 10 = 0
- PRINT%(10,20) "Parsing multi-line statements…"
- PRINT%(10,40) "Currently on line#";lnCount
- END IF
- linesAdded = FN parseLineColons(lnCount)
- NEXT
- END FN
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine saves the entire converted file to disk
- '
- LOCAL FN saveIt
- ppos = INSTR(1, gFilename$, ".")
- LONG IF ppos > 1
- gFilename$ = LEFT$(gFilename$, ppos-1)
- END IF
-
- saveAs$ = gFilename$ + ".CONV"
- filename$ = FILES$ (_fSave, "Save converted file as:", saveAs$, volRefNum%)
- LONG IF LEN(filename$)
- CURSOR _watchCursor
- CLS: TEXT _monaco, 9
- PRINT%(10,20) "Saving converted source file to disk…"
-
- DEF OPEN "TEXT"
- OPEN "O",1 , filename$, , volRefNum%
- LONG IF SYSERROR = _noErr
- PRINT #1, source$
- FOR lineCnt = 0 TO gHeaderLines 'output our header info
- source$ = INDEX$(lineCnt, _hedIndx)
- PRINT #1, source$
- NEXT
- FOR lineCnt = 0 TO gTotalLines 'output the revised source text
- remark$ = INDEX$(lineCnt, _remIndx)
- LONG IF remark$ <> ""
- IF LEFT$(remark$, 1) <> "'" THEN remark$ = "'" + remark$
- END IF
- source$ = INDEX$(lineCnt, _srcIndx) + remark$ 'add remarks back into source
- PRINT #1, source$ 'save to file
- NEXT
- CLOSE #1
- XELSE
- item = FN doAlrt ("Unable to save converted file.")
- END IF
- END IF
- CALL INITCURSOR
- END FN
-
-
-
-
-
-
- LOCAL FN parseSUB$ (srcCount)
- source$ = INDEX$ (srcCount, _srcIndx)
- spos = INSTR (1, source$, "END SUB")
- LONG IF spos
- source$ = "END FN"
- INC (gExitSub)
- XELSE
- spos = INSTR (1, source$, "SUB ")
- LONG IF spos = 1
- source$ = RIGHT$ (source$, LEN(source$) - 4)
- spos = INSTR (1, source$, "STATIC")
- LONG IF spos
- source$ = LEFT$ (source$, spos - 1)
- source$ = "LONG FN " + source$
- XELSE
- source$ = "LOCAL FN " + source$
- END IF
- END IF
- END IF
- INDEX$ (srcCount, _srcIndx) = source$
- END FN
-
-
-
- SEGMENT
-
-
- ' ------------------------------------------------------------------------
- ' this routine reads in the QB->FB data file that describes the differences
- ' between the two products syntax
- '
- LOCAL FN ReadDataFile
- CLS
- PRINT%(10,20) "Now loading conversion file into memory…"
- CURSOR _watchCursor
-
- OPEN "I",1,"QB->FB.data",,SYSTEM (_aplVol) 'must be in same folder...
- LONG IF SYSERROR = _noErr
- keyCount = -1 'init our var
- DO
- INC(keyCount) 'increment keyword var
- LINE INPUT #1, gConv$(0,keyCount) 'get old syntax
- LINE INPUT #1, gConv$(1,keyCount) 'get new syntax
-
- FN stripLeadChar (gConv$(0,keyCount), _space, 1) 'strip any front spaces
- FN stripLeadChar (gConv$(1,keyCount), _space, 1)
-
- UNTIL EOF(1) OR gConv$(0,keyCount) = "" 'eof or empty keyword ends file input
- DEC(keyCount) 'increment keyword var
- CLOSE #1
- XELSE
- item = FN doAlrt("Unable to open “QB->FB.data” file.")
- END
- END IF
- CALL INITCURSOR 'close keyword file
- END FN = keyCount
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine extracts the keyword from the conversion data file
- '
- ' keyCount = keyword element to extract from gConv$()
- ' keyword$ = actual keyword to search for
- '
- LOCAL FN GetKeyWord$ (keyCount)
- charPos = 0
- qbSyntax$ = gConv$ (0, keyCount)
- strPtr& = @qbSyntax$
- DO 'skip all chars not alphabetical in nature
- INC (charPos)
- char = PEEK(strPtr& + charPos)
- UNTIL (char => _"A" AND char <= _"Z") OR (char => _"a" AND char <= _"z")
- startPos = charPos
- DO 'now cycle thru keyword until finished
- INC (charPos)
- char = PEEK(strPtr& + charPos)
- IF char = _"_" THEN POKE strPtr& + charPos, _space
- UNTIL char = _space OR char = _openP OR charPos > PEEK(strPtr&)
- keyword$ = MID$ (qbSyntax$, startPos, charPos - startPos)'get keyword from line
- END FN = keyword$
-
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine does all the work of converting the original QB keywords to
- '
- LOCAL FN CountChar (@synPtr&, charType)
- charCount = 0
- charPos = 1
- strLen = PEEK (synPtr&)
- DO
- char = PEEK (synPtr& + charPos)
- LONG IF char = charType
- INC (charCount)
- END IF
- INC (charPos)
- UNTIL charPos > strLen
- END FN = charCount
-
-
-
-
-
-
-
- ' -----------------------------------------------------------------
- '
- LOCAL FN SkipParens (srcPtr&, charPos)
- parenCount = 1
- DO
- INC (charPos)
- char = PEEK (srcPtr& + charPos) 'get next char in source
- SELECT char
- CASE _openP : INC (parenCount)
- CASE _closeP : DEC (parenCount)
- END SELECT
- UNTIL char = _closeP AND parenCount = 0
- END FN = charPos
-
-
-
-
-
-
- ' -----------------------------------------------------------------
- ' this routine extracts all characters between the starting and ending
- ' points of the specified string. the start point is defined by charPos,
- ' the ending point by a comma or when the search exceeeds the search
- ' strings length. the result is placed into the parameter pointed to by
- ' paramPtr.
- '
- ' srcPtr& = pointer to source string
- ' charPos = starting position of search
- '
- LOCAL FN ExtractParams (srcPtr&, charPos)
- FN StartFN (4)
- srcLen = PEEK (srcPtr&) 'setup initial variables
- startPos = charPos
- paramCount = 1 'parameter element count
- endExtract = _false 'loop until finished
- :
- DO
- char = PEEK (srcPtr& + charPos) 'get next char in source
- SELECT 'now act upon it
- CASE char = _comma OR charPos > srcLen OR char = _closeP'is it a comma or end of source
- paramLen = charPos - startPos 'get length to strip
- paramPtr& = @gParam$(paramCount) 'get pointer to storage
- POKE paramPtr&, paramLen 'put length into storage string
- BLOCKMOVE srcPtr& + startPos, paramPtr& + 1, paramLen'no pass parameter
- : 'do some cleaning up of parameters
- FN stripLeadChar (gParam$(paramCount), _space, 1)'strip any leading spaces
- LONG IF INSTR (1, gParam$(paramCount), "(") = 1 'does it start with a parenthesis?
- FN stripLeadChar (gParam$(paramCount), _openP, 1)'strip any leading spaces
- tmp$ = ")" : tmp2$ = ""
- FN replaceSomething (gParam$(paramCount), PEEK(paramPtr&), tmp$, tmp2$)
- END IF
- :
- INC (paramCount)
- startPos = charPos + 1 'skip past last comma
- CASE char = _openP
- charPos = FN SkipParens (srcPtr&, charPos)
- END SELECT
- IF startPos <= srcLen THEN INC (charPos) ELSE endExtract = _true
- UNTIL endExtract = _true
- FN StopFN (4)
- :
- END FN = charPos
-
-
-
-
-
-
-
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' use this routine to locate a specific char within a string. somewhat analogous
- ' to INSTR but works with a string pointer instead of the string itself
- '
- LOCAL FN FindChar (srcPtr&, charPos, char)
- strLen = PEEK (srcPtr&)
- WHILE PEEK (srcPtr& + charPos) <> char AND charPos <= strLen
- INC (charPos)
- WEND
- IF PEEK (srcPtr& + charPos) <> char THEN charPos = 0
- END FN = charPos
-
-
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine does all the work of converting the original QB keywords to
- ' FB format
- '
- LOCAL FN GetAndFillParams (srcPtr&, keyPtr&, keyCount, charPos)
-
- FN StartFN (3)
-
- FOR count = 0 TO 9
- gParam$(count) = ""
- gStmnt$(count) = ""
- NEXT count
-
- keyType = ASC(gConv$(_qb, keyCount))
- gParam$(0) = CHR$ (keyType)
-
- SELECT keyType
- CASE _caret
- CASE _att
- charPos = FN FindChar (srcPtr&, charPos, _space)
- IF charPos <> 0 THEN FN ExtractParams (srcPtr&, charPos)
-
- CASE _pound
- charPos = FN FindChar (srcPtr&, charPos, _openP) + 1
- FN ExtractParams (srcPtr&, charPos)
-
- CASE _asterisk
- origPos = charPos
- charPos = FN FindChar (srcPtr&, charPos, _space)
- LONG IF charPos = 0
- charPos = FN FindChar (srcPtr&, origPos, _openP)
- END IF
- FN ExtractParams (srcPtr&, charPos + 1)
-
- CASE ELSE
- tmp$ = "Conversion type “" + syntax$ + "” in line#" + STR$(keyCount)
- item = FN doAlrt (tmp$)
- IF item = 2 THEN END
- END SELECT
-
- charPos = INSTR (1, gConv$ (_qb, keyCount), "_") 'strip underscores from keyword
- tmp$ = "_" : tmp2$ = " "
- IF charPos THEN FN replaceSomething (syntax$, charPos, tmp$, tmp2$)
- FN StopFN (3)
- END FN
-
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine takes the parameter variables extracted from the original
- ' source line and places them into the correct fb syntax sequence.
- '
- ' srcPtr& = pointer to original source string
- ' keyPtr& = pointer to keyword
- ' keyCount = element count in gConv$()
- '
- LOCAL FN ConvertSyntax (srcPtr&, keyPtr&, keyCount)
- FN StartFN (8)
- DIM source$
- DIM keyword$
- :
- BLOCKMOVE srcPtr&, @source$, PEEK (srcPtr&) + 1 'get us some strings to work with
- BLOCKMOVE keyPtr&, @keyword$, PEEK(keyPtr&) + 1
- ucSource$ = UCASE$(source$)
- :
- paramCount = 9 'start at the top
- WHILE gParam$ (paramCount) = "" 'is this element empty?
- DEC (paramCount) 'then reduce by one
- WEND 'until an element is filled
- :
- startPos = INSTR (1, ucSource$, keyword$) 'get starting position of keyword
- LONG IF paramCount = 0 'no parameters so set to end of keyword
- endPos = startPos + PEEK(@keyword$)
- XELSE 'got a parameter
- endPos = INSTR (startPos, ucSource$, UCASE$(gParam$ (paramCount))) + LEN (gParam$ (paramCount))
- END IF
- LONG IF endPos = PEEK(@source$) 'make sure we get that last
- INC(endPos) 'parenthesis in a source code line
- END IF
- :
- SELECT gParam$(0) 'any special handling required?
- CASE "*" : 'check for presence of CALL
- charPos = INSTR (1, ucSource$, "CALL ") 'is CALL there?
- LONG IF charPos <> 0 AND charPos < startPos 'make sure its before the keyword
- startPos = startPos - 5 'then adjust start position
- END IF
- CASE ELSE
- END SELECT
- :
- 'TRON p
- LONG IF endPos > startPos
- oldkey$ = MID$ (source$, startPos, endPos - startPos)'and ending pos
- : 'get the entire keyword with variables
- tmp2$ = gConv$ (_fb, keyCount)
- FN replaceSomething (source$, startPos, oldkey$, tmp2$)
- : 'and replace it with new line
- charPos = 1
- paramCount = 1
- WHILE paramCount < 10
- oldkey$ = STR$(paramCount) 'make param a match string
- tmp$ = " " : tmp2$ = "~"
- FN replaceSomething (oldkey$, 1, tmp$, tmp2$) 'insert tilde char to match string
- charPos = INSTR(charPos, source$, oldkey$) 'get its position in source
- tmp2$ = gParam$ (paramCount)
- IF charPos <> 0 THEN FN replaceSomething (source$, charPos, oldkey$, tmp2$)
- charPos = 1
- INC (paramCount)
- WEND
- :
- BLOCKMOVE @source$, srcPtr&, PEEK(@source$) + 1 'replace original with modified
- XELSE
- tmp$ = "Error in parameter#" + STR$(paramCount) + "//" + source$
- item = FN doAlrt (tmp$)
- IF item = 1 THEN END
- END IF
- FN StopFN (8)
- END FN
-
-
-
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine does all the work of converting the original QB keywords to
- ' FB format
- '
- ' charPos = char position where match was found
- ' srcPtr& = pointer to original source$
- ' keyPtr& = pointer to keyword$
- ' keyCount = element position of key in gConv$()
- '
- LOCAL
- DIM source$
- LOCAL FN UpdateSyntax (charPos, @srcPtr&, @keyPtr&, keyCount)
-
- charPos = charPos + PEEK(keyPtr&) 'skip start char past keyword
- FN GetAndFillParams (srcPtr&, keyPtr&, keyCount, charPos)'fill params for keyword
-
- FN StartFN (2)
- SELECT ASC(gParam$(0)) 'now execute different conversion types
- CASE _caret 'insert helpful msg
- tmp$ = "" : tmp2$ = gConv$ (_fb, keyCount)
- FN replaceSomething (=srcPtr&, 1, tmp$, tmp2$)
-
-
- CASE _att 'convert non-parenthesis keywords
- 'FN StripParams (srcPtr&, charPos)
- FN ConvertSyntax (srcPtr&, keyPtr&, keyCount)
-
-
- CASE _pound 'convert non-parenthesis keywords
- charPos = FN FindChar (srcPtr&, 1, _openP) 'is there a parenthesis
- 'FN StripParams (srcPtr&, charPos) 'strip parenthesis params
- FN ConvertSyntax (srcPtr&, keyPtr&, keyCount)
-
-
- CASE _asterisk 'convert toolbox calls
- FN ConvertSyntax (srcPtr&, keyPtr&, keyCount)
- BLOCKMOVE srcPtr&, @source$, PEEK(srcPtr&) + 1 'get source itself (sigh!)
- DO
- charPos = INSTR (charPos, source$, "VARPTR") 'is a VARPTR present?
- LONG IF charPos <> 0 'if so, fix it to work
- tmp$ = "" : tmp2$ = "#"
- FN replaceSomething (source$, charPos, tmp$, tmp2$)'add # to use value of address
- charPos = charPos + 6 'make sure to skip last VARPTR
- END IF
- UNTIL charPos = 0
- BLOCKMOVE @source$, srcPtr&, PEEK(@source$) + 1 'get source itself (sigh!)
-
- CASE ELSE
- item = FN doAlrt ("Incorrect conversion type in data file.")
- END
- END SELECT
- FN StopFN (2)
- END FN
-
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine see's if a keyword is really there
- '
- '
- LOCAL FN CheckKeyword (@srcPtr&, charPos, @keyPtr&)
- beforFlag = _false
- afterFlag = _false
- srcLen = PEEK (srcPtr&)
- keyLen = PEEK (keyPtr&)
- LONG IF charPos <> 1
- beforChar = PEEK(srcPtr& + charPos - 1) 'keyword
- LONG IF beforChar = _space OR beforChar = _colon OR beforChar = _comma
- beforFlag = _true
- END IF
- XELSE
- beforFlag = _true
- END IF
- afterChar = PEEK(srcPtr& + charPos + keyLen)
- LONG IF afterChar = _space OR afterChar = _colon OR afterChar = _openP OR afterChar = _pound
- afterFlag = _true
- END IF
- END FN = (afterFlag AND beforFlag)
-
-
-
-
-
-
- ' ------------------------------------------------------------------------
- ' this routine does all the work of converting the original QB keywords to
- ' FB format
- '
- LOCAL FN convertLines
- DIM 255 source$
-
- maxKeyCount = FN ReadDataFile
- LONG IF maxKeyCount > 0
- FN StartFN (1)
- CLS
- CURSOR _watchCursor
- FOR srcCount = 0 TO gTotalLines
- 'TRON x
- :
- FN parseSUB$ (srcCount)
- 'FN parseXelse$ (srcCount)
- :
- source$ = INDEX$ (srcCount, _srcIndx)
-
- PRINT%(10,20) "Converting keyword syntax from QB to FB format…"
- PRINT%(10,40) "Now converting line#";srcCount
-
- LONG IF source$ <> "" 'do we have something to convert?
- DEF TRUNCATE (source$) 'strip all spaces at end
- FN stripLeadChar (source$, _space, 1) 'and the beginning
- ucSource$ = UCASE$(source$)
- keyCount = 0
- DO
- keyword$ = FN GetKeyWord$ (keyCount) 'get keyword to search for
- keyLen = PEEK(@keyword$)
- srcLen = PEEK(@source$)
- :
- LONG IF keyword$ <> "" AND (keyLen <= srcLen)
- charPos = INSTR (1, ucSource$, keyword$)
- LONG IF charPos <> 0 AND keyCount <= maxKeyCount'is it in this source line?
- : 'if so, replace old syntax with new
- keyFlag = FN CheckKeyword (source$, charPos, keyword$)
- LONG IF keyFlag
- FN UpdateSyntax (charPos, source$, keyword$, keyCount)
- keyCount = maxKeyCount
- END IF
- :
- END IF
- END IF
- INC (keyCount) 'add 1 to get next keyword
- UNTIL keyCount > maxKeyCount OR keyCount > _maxKeywords'cycle thru all keywords
- INDEX$ (srcCount, _srcIndx) = source$ 'replace original source line
- END IF 'source$ is not empty
- NEXT srcCount
- XELSE
- BEEP : PRINT "Error count =";maxKeyCount
- END IF
- FN StopFN (1)
- CALL INITCURSOR
- END FN
-
-
-
-
-
-
- LOCAL
- DIM srcTmp$(300)
- LOCAL FN formatProgram
- INDEX$(0,_hedIndx) = "'QB program converted to FutureBASIC syntax"
- INDEX$(1,_hedIndx) = "'Program name was: " + gFilename$
- INDEX$(2,_hedIndx) = ""
- INDEX$(3,_hedIndx) = "'-------------------- Header ---------------------------"
- INDEX$(4,_hedIndx) = "'Put a RESOURCES statement here if needed"
- INDEX$(5,_hedIndx) = ""
- INDEX$(6,_hedIndx) = "COMPILE 0, _caseInsensitive _strResources _macsbugLabels "
- INDEX$(7,_hedIndx) = ""
- INDEX$(8,_hedIndx) = "'-------------------- Globals --------------------------"
- INDEX$(9,_hedIndx) = ""
- INDEX$(10,_hedIndx) = "'Place DIM or GLOBALS statements here as required"
- INDEX$(11,_hedIndx) = "END GLOBALS"
- INDEX$(12,_hedIndx) = ""
- INDEX$(13,_hedIndx) = "'-------------------- Functions ------------------------"
- gHeaderLines = 13
-
- FOR x = 0 TO gTotalLines
-
- source$ = INDEX$(x, _srcIndx) 'move SUBs to function section of program
- LONG IF INSTR(1,source$,"LONG FN") OR INSTR(1,source$,"LOCAL FN")
- counter = 0
- curPos = x
- DO
- srcTmp$(counter) = source$
- INC(counter)
- INC(curPos)
- source$= INDEX$(curPos, _srcIndx)
- UNTIL INSTR(1,source$,"END FN")
- srcTmp$(counter) = source$
-
- FOR z = 0 TO counter
- INDEX$(gHeaderLines, _hedIndx) = srcTmp$(z)
- INC(gHeaderLines)
- NEXT
- INC(gHeaderLines)
-
- FOR z = 0 TO counter
- INDEX$ D (x, _srcIndx)
- DEC(gTotalLines)
- NEXT
- END IF
-
- source$ = INDEX$(x, _srcIndx) 'global variables?
- LONG IF INSTR(1,source$,"DIM SHARED ") 'global variables?
- source$ = RIGHT$(source$, LEN(source$)-11)
- source$ = "DIM "+ source$
- INDEX$ I(8, _srcIndx) = source$ 'insert the global vars into global area
- INC(gHeaderLines)
- INDEX$ D (x, _srcIndx)
- DEC(gTotalLines)
- END IF
-
-
- source$ = INDEX$(x,_srcIndx) 'check for resource file being opened...
- srcTmp$ = source$
- source$ = UCASE$(source$)
- LONG IF INSTR(1,source$,"OPENRESFILE ") 'resources file?
- tpos = INSTR(1,srcTmp$,CHR$(_quote)) 'double quotes?
- fname$ = ""
- LONG IF tpos
- DO
- fname$ = fname$ + CHR$(PEEK(@srcTmp$+tpos))
- tpos = tpos +1
- UNTIL PEEK(@srcTmp$+tpos) = 34
- fname$ = fname$ + CHR$(_quote)
- source$ = "RESOURCES "+fname$
- INDEX$ (4, _srcIndx) = source$ 'insert the global vars into global area
- INDEX$(x, _srcIndx) = "see RESOURCES at top of program -->"+srcTmp$
- END IF
- END IF
-
- NEXT
- END FN
-
-
-
- '----------------------- Main --------------------------
-
- COMPILE LONG IF _debug
- TROFF
- COMPILE END IF
- FLUSHEVENTS
- FN initialize
- FN OpenFile
- LONG IF gFilename$ <> ""
- start& = FN TICKCOUNT
- CURSOR _watchCursor
- :
- FN parseLabels
- FN fixLineRefs
- FN convertLines
- FN formatProgram
- FN saveIt
- :
- CALL INITCURSOR
- END IF
- '
- CLS
- SOUND "Stopped"
- TEXT _monaco, 9, _boldBit%, 0 : COLOR _zRed
- PRINT%(10,20) "Conversion is done!"
- TEXT _monaco, 9, 0, 0 : COLOR _zBlack
- totalTime! = ((FN TICKCOUNT - start&)/60)/60
- PRINT%(10,40) "Total Conversion Time: ";USING "###.###";totalTime!; " minutes"
- PRINT%(10,60) "Press mouse button to quit."
- '
- DO
- UNTIL FN BUTTON
- END
-